package vn.edu.saigontech.ncms.web.study;

import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateSecondTestAction extends AbstractValidator {
	private String memberId;
	private String finalSpokenDate;
	private String finalWrittenDate;
	private String listening;
	private String speaking;
	private String grammar;
	private String reading;
	private String writing;
	private String fee;

	@Override
	public String check() {
		if(Checker.isEmpty(memberId)) {
			this.sendKeyError("validator.required", "student");
		}
		if (Checker.isEmpty(finalSpokenDate)) {
			this.sendKeyError("validator.required", "finalSpokenDate");
		}
		if (!Checker.isDate(finalSpokenDate, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "finalSpokenDate",
					"format.date");
		}
		if (Checker.isEmpty(finalWrittenDate)) {
			this.sendKeyError("validator.required", "finalWrittenDate");
		}
		if (!Checker.isDate(finalWrittenDate, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "finalWrittenDate",
					"format.date");
		}
		if (Checker.isEmpty(listening)) {
			listening = "0";
		}
		if (!Checker.isDouble(listening)
				|| !Checker.isInRange(Double.valueOf(listening), 0, 100)) {
			this.sendKeyError("validator.invalid", "listeningScore");
		}
		if (Checker.isEmpty(speaking)) {
			speaking = "0";
		}
		if (!Checker.isDouble(speaking)
				|| !Checker.isInRange(Double.valueOf(speaking), 0, 100)) {
			this.sendKeyError("validator.invalid", "speakingScore");
		}
		if (Checker.isEmpty(grammar)) {
			grammar = "0";
		}
		if (!Checker.isDouble(grammar)
				|| !Checker.isInRange(Double.valueOf(grammar), 0, 100)) {
			this.sendKeyError("validator.invalid", "grammarScore");
		}
		if (Checker.isEmpty(reading)) {
			reading = "0";
		}
		if (!Checker.isDouble(reading)
				|| !Checker.isInRange(Double.valueOf(reading), 0, 100)) {
			this.sendKeyError("validator.invalid", "readingScore");
		}
		if (Checker.isEmpty(writing)) {
			writing = "0";
		}
		if (!Checker.isDouble(writing)
				|| !Checker.isInRange(Double.valueOf(writing), 0, 100)) {
			this.sendKeyError("validator.invalid", "writtenScore");
		}

		if (!Checker.isEmpty(fee)) {
			if (!Checker.isDouble(fee)) {
				this.sendKeyError("validator.invalid", "fee");
			}
		}
		return this.toSuccess();
	}

	public String getListening() {
		return listening;
	}

	public void setListening(String listening) {
		this.listening = listening;
	}

	public String getSpeaking() {
		return speaking;
	}

	public void setSpeaking(String speaking) {
		this.speaking = speaking;
	}

	public String getGrammar() {
		return grammar;
	}

	public void setGrammar(String grammar) {
		this.grammar = grammar;
	}

	public String getReading() {
		return reading;
	}

	public void setReading(String reading) {
		this.reading = reading;
	}

	public String getWriting() {
		return writing;
	}

	public void setWriting(String writing) {
		this.writing = writing;
	}

	public String getFee() {
		return fee;
	}

	public void setFee(String fee) {
		this.fee = fee;
	}

	public String getFinalSpokenDate() {
		return finalSpokenDate;
	}

	public void setFinalSpokenDate(String finalSpokenDate) {
		this.finalSpokenDate = finalSpokenDate;
	}

	public String getFinalWrittenDate() {
		return finalWrittenDate;
	}

	public void setFinalWrittenDate(String finalWrittenDate) {
		this.finalWrittenDate = finalWrittenDate;
	}

	public String getMemberId() {
		return memberId;
	}

	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}
}
